package com.yw.swagger.tool.config;

import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import com.yw.swagger.customNote.fyh;
import com.yw.swagger.customNote.qw;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


/**
 * @author HDY
 * @date 2019/10/18 18:48
 */
@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
public class swaggerConfig{
    private Boolean switchs;
    //获取当前运行环境
    public void setEnvironment (Environment environment){
        Profiles profiles = Profiles.of("dev");
        this.switchs = environment.acceptsProfiles(profiles);
    }
    @Bean
    public Docket api(Environment environment){
        this.setEnvironment(environment);
        return new Docket(DocumentationType.SWAGGER_2)
                .useDefaultResponseMessages(false)
                .groupName("祁旺")
                .enable(switchs)
                .select()
                .apis(RequestHandlerSelectors.withMethodAnnotation(qw.class))
                .build()
                .apiInfo(apiInfo());
    }
    @Bean
    public Docket api1(Environment environment){
        this.setEnvironment(environment);
        return new Docket(DocumentationType.SWAGGER_2)
                .useDefaultResponseMessages(false)
                .groupName("付宇航")
                .enable(switchs)
                .select()
                .apis(RequestHandlerSelectors.withMethodAnnotation(fyh.class))
                .build()
                .apiInfo(apiInfo());
    }
    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("亿网后台接口")//标题
                    .description("支持 多人员分组  支持 根据环境进行开关接口显示控制   默认权限码 A8383U3243")//描述
                .version("1.0.0")
                .build();
    }
}
